package p17_从advisor到aspect;

import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 这里准备了一个低级切面，一个低级切面只包含一组 切点+通知
 */
@Configuration
public class MyAdvisor {

    //这是一个低级切面
    @Bean
    public Advisor advisor1() {
        //切点
        AspectJExpressionPointcut pt = new AspectJExpressionPointcut();
        pt.setExpression("execution(* foo())");
        //通知
        MethodInterceptor advice = invocation -> {
            System.out.println("advisor before....");
            Object proceed = invocation.proceed();
            System.out.println("advisor after...");
            return proceed;
        };
        //低级切面，只包含一组 切点+通知
        return new DefaultPointcutAdvisor(pt, advice);
    }

}
